{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用梯度上升法求解主成分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.empty((100, 2))\n",
    "X[:, 0] = np.random.uniform(0., 100., size=100)\n",
    "X[:, 1] = 0.75 * X[:, 0] + 3. + np.random.normal(0, 10., size=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGm5JREFUeJzt3X+sXGWdx/H3t7cXuBXlFqkKF5rWSGAFAtUbwlrXSHFFBaFBUHeNy+6S9J9df6CLXnYTf2yyoQaz6CbGpAHdukukCqSwYsQNrdldElhvKQoIrCxg6aVKXXrVyA3clu/+MTMw3J6ZOWfm/Hiecz6vpGnndObOM+ee+Z7nfJ/v8xxzd0REpL6WVd0AEREplgK9iEjNKdCLiNScAr2ISM0p0IuI1JwCvYhIzSnQi4jUnAK9iEjNKdCLiNTc8jLf7LjjjvM1a9aU+ZYiItHbtWvXr9191bCvLzXQr1mzhtnZ2TLfUkQkemb2i1Fer9SNiEjNKdCLiNScAr2ISM0p0IuI1JwCvYhIzZVadSMiUhfbd89x7Z2P8vT8AidMTnDV+aewcd1U1c1KpEAvIpLR9t1zXH3rAywsHgJgbn6Bq299ACDIYK/UjYhIRtfe+ehLQb5jYfEQ1975aEUt6k+BXkQko6fnFzJtr5oCvYhIRidMTmT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BaXc/HRgDPkz9j4N/Bt6zZFuv3/t7gZPbfzYBX0/zBkEFeuBs4DF3f9zdXwBuAi6uuE2Fc/d97n5f+9+/o/UFn6L12be2n7YV2FhNC4tnZicCFwDXtx8bsAG4uf2Uun/+1wDvAG4AcPcX3H2eBh0DbcuBCTNbDqwA9lHz48Dd/wN4dsnmXr/3i4Fvecs9wKSZHT/oPUIL9FPAU12P97a3NYaZrQHWAfcCr3f3fdA6GQCvq65lhfsK8Bngxfbj1wLz7n6w/bjux8Ibgf3AN9vpq+vN7FU06Bhw9zngy8AeWgH+N8AumnUcdPT6vQ8VI0ML9JawrTFlQWZ2NHAL8El3/23V7SmLmV0IPOPuu7o3Jzy1zsfCcuAtwNfdfR3we2qcpknSzkNfDKwFTgBeRStVsVSdj4NBhvpehBbo9wIndT0+EXi6oraUyszGaQX5G9391vbmX3Uuy9p/P1NV+wq2HrjIzJ6kla7bQKuHP9m+hIf6Hwt7gb3ufm/78c20An9TjgGAdwFPuPt+d18EbgXeRrOOg45ev/ehYmRogf7HwMntUfYjaA3E3F5xmwrXzkffADzs7v/Y9V+3A5e3/305cFvZbSuDu1/t7ie6+xpav/Md7v4RYCdwaftptf38AO7+S+ApM+vcmf484Gc05Bho2wOcY2Yr2t+Jzj5ozHHQpdfv/Xbgz9rVN+cAv+mkePpy96D+AO8D/gf4X+Dvqm5PSZ/57bQuv34K3N/+8z5aeeq7gJ+3/z626raWsC/eCXyv/e83Av8NPAZ8Fziy6vYV/NnPAmbbx8F2YGXTjgHgi8AjwIPAvwBH1v04AL5Na0xikVaP/Ypev3daqZuvtePjA7QqlAa+h2bGiojUXGipGxERyZkCvYhIzSnQi4jUnAK9iEjNKdCLiNScAr2ISM0p0IuI1JwCvYhIzf0/gksvUWKM/roAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:, 0], X[:, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 去平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def demean(X):\n",
    "    return X - np.mean(X, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_demean = demean(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGgVJREFUeJzt3X+sXHWZx/H3w+UC10W5KkXwtt02WVKXHypygyb9R+uPIpDSBVwxxEUlaUww0Y1WWvhjIdFQ00Rw449NoyaQJSlEsNSVTUWLfyxZ1FsKEoS6BBS5sFKzXDW2u1zKs3/MmTKde2bmzMz58f2e83klDffOzJ35zuHe53zn+T7f55i7IyIi9Xdc1QMQEZFyKOCLiDSEAr6ISEMo4IuINIQCvohIQyjgi4g0hAK+iEhDKOCLiDSEAr6ISEMcX/UAOp166qm+atWqqochIhKVffv2/cHdlw16XFABf9WqVczNzVU9DBGRqJjZb7M8TikdEZGGUMAXEWkIBXwRkYZQwBcRaQgFfBGRhgiqSkdEpC527Z9n+54DPL9wmLdOT7F5/Ro2njdT6ZgU8EVEcrZr/zxb73mMw4tHAJhfOMzWex4DqDToK6UjIpKz7XsOHA32bYcXj7B9z4GKRtSigC8ikrPnFw4PdXtZFPBFRHL21umpoW4viwK+iEjONq9fw9TkxDG3TU1OsHn9mopG1KJFWxGRnLUXZlWlIyLSABvPm6k8wHdTSkdEpCEU8EVEGkIBX0SkIRTwRUQaQgFfRKQ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AO+F7ykGiOgQL+AGa2AZh390e77poBftfx/XPJbXX3KeDfk6+bdAya9F6XMLNVwHnAz4C3uPsL0DopAKdVN7JS3Eprwvdq8v2bgYWOSVA0vwu6AApgZj8GTk+56wbgeuBDaT+Wclu0JU/9joG735s85gZaH/PvaP9YyuOjPQYDNOm9HsPMTgbuBj7n7n9qTXCbwcwuAV50931m9t72zSkPjeJ3QQEfcPcPpN1uZucCq4FHk1/y5cDDZnYBrbP6io6HLweeL3iohel1DNrM7GrgEuD9/lotb62OwQBNeq9HmdkkrWB/h7vfk9z8ezM7w91fSNKYL1Y3wsKtBTaY2UXAScAbaM34p83s+GSWH83vglI6fbj7Y+5+mruvcvdVtP7o3+Xu/w3sBv4hqdZ5D/DH9sfcujGzC4HrgA3ufqjjrt3AlWZ2opmtprWA/fMqxliCXwBnJtUZJ9BarN5d8ZgKleSqvwM84e5f7bhrN3B18vXVwL1lj60s7r7V3Zcnf/9XAnvd/SrgAeCK5GHRHAPN8Ed3H3ARrYXKQ8Anqx1Oob4OnAjcn3zSecjdP+3uj5vZXcCvaKV6rnX3IxWOszDu/oqZfQbYA0wA33X3xyseVtHWAh8HHjOzR5Lbrge2AXeZ2TW0Ktc+UtH4qnQdsNPMvgTsp3ViDJ522oqINIRSOiIiDaGALyLSEAr4IiINoYAvItIQCvgiIg2hgC8i0hAK+CIiDaGALyLSEP8P+LZqM1oQLpQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X_demean[:, 0], X_demean[:, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.6290081223123707e-15"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X_demean[:, 0]) # 基本是0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-9.5923269327613531e-15"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X_demean[:, 1]) # 基本是0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 梯度上升法的实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(w, X):\n",
    "    return np.sum((X.dot(w)**2)) / len(X) # X必须是已经去平均化的矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def df_math(w, X):\n",
    "    return X.T.dot(X.dot(w) * 2. / len(X))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def df_debug(w, X, epsilon=0.0001):\n",
    "    res = np.empty(len(w))\n",
    "    for i in range(len(w)):\n",
    "        w_1 = w.copy()\n",
    "        w_1[i] += epsilon\n",
    "        w_2 = w.copy()\n",
    "        w_2[i] -= epsilon\n",
    "        res[i] = (f(w_1, X) - f(w_2, X)) / (2 * epsilon)\n",
    "    return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''把向量转换为单位方向向量'''\n",
    "def direction(w):\n",
    "    return w / np.linalg.norm(w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def gradient_ascent(df, X, initial_w, eta, n_iters = 1e4, epsilon=1e-8):\n",
    "    \n",
    "    w = direction(initial_w)\n",
    "    cur_iter = 0\n",
    "\n",
    "    while cur_iter < n_iters:\n",
    "        gradient = df(w, X)\n",
    "        last_w = w\n",
    "        # 这里与梯度下降法不同，关键之处\n",
    "        w = w + eta * gradient\n",
    "        # 转换为单位方向向量\n",
    "        w = direction(w)\n",
    "        if(abs(f(w, X) - f(last_w, X)) < epsilon):\n",
    "            break\n",
    "            \n",
    "        cur_iter += 1\n",
    "\n",
    "    return w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.53527228,  0.24809709])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initial_w = np.random.random(X.shape[1])\n",
    "initial_w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "eta = 0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'不能使用StandardScaler标准化数据'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''不能使用StandardScaler标准化数据'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.78316652,  0.62181203])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gradient_ascent(df_debug, X_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.78316652,  0.62181203])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gradient_ascent(df_math, X_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uI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3T8zsyPcfVsjjflycS3M3GxgrpmdBuwPvJ2oxz/FzPZt9PJL87uglM4E3P0Zdz/M3We4+wyiP/oPufv/A1YBn2tU63wEeLX5NbdqzOxU4EpgrrvvanloFXCume1nZjOJBrD/uYg25uBfgKMa1RmTiQarVxXcpkw1ctW3Axvd/caWh1YB5zd+Ph+4L++25cXdF7n7tMbf/7nAGnc/D3gE+FTjaaU5B+rh9+4B4DSigcpdwAXFNidTfw3sBzzU+KbzuLt/0d03mNldwL8TpXoucvc9BbYzM+7+upldDKwGJgHfcfcNBTcra7OBzwLPmNlTjfuuApYAd5nZF4gq184pqH1FuhJYYWY3AOuJLozB00xbEZGaUEpHRKQmFPBFRGpCAV9EpCYU8EVEakIBX0SkJhTwRURqQgFfRKQmFPBFRGri/wMXtI93UOx1GgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "w = gradient_ascent(df_math, X_demean, initial_w, eta)\n",
    "plt.scatter(X_demean[:, 0], X_demean[:, 1])\n",
    "plt.plot([0, w[0]*30], [0, w[1]*30], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.empty((100, 2))\n",
    "X2[:, 0] = np.random.uniform(0., 100.0, size=100)\n",
    "X2[:, 1] = 0.75 * X2[:, 0] + 3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGsRJREFUeJzt3X+Q3PV93/HnS8cRVs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i8kNRPOcwfjIg9yenXK//0Sl5PLlT7MrIWuF7Sq5RLauso99gHkn+SQz7v+zHgWEQcTI4foxzweb/fHwJ+FBFjETEJ7AF+m/zf74p697dlWdfJgf5d4KLkCfiZlB+e7F3gNmUiqRvfD7wQEX8640d7gY3J9xuBx9vdtixFxJ0RcUFErKJ8f5+MiFuBp4Cbksvy+Ln/HnhN0sXJqauBH5Dz+0251LJG0uLk73zlc+f6fs9Q7/7uBf5tMtplDfDzSmmmaRHRsV/AtZQXAPsh8McL3Z4MP+e/ovxPrO8DzyZf11KuJ+8HXkpez1notmb4v8FVwDeT798L/B3wMvAo8GsL3b4MPu9lwHByz4vAkl6438AXgBeB54H/BfxaHu83sJvyc4JJyj3w2+vdX8oll68kOTdKeRTQnH6vZ4qameVEJ5dczMysCQ50M7OccKCbmeWEA93MLCcc6GZmOeFANzPLCQe6mVlOONDNzHLi/wPDl9uXBsiOagAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:, 0], X2[:, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2_demean = demean(X2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "w2 = gradient_ascent(df_math, X2_demean, initial_w, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHsBJREFUeJzt3XuYlHX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nq9OThWbq4AHg1+Lvd7Lvf7S8nMBgMjgBXA4e6+FeL/KACHFa5lOfM94h243cHrQ4CmpE5OKP7cS34DlL1lZk8AR6R46wbgeuCMVB9Lcaxkhjl1dc/u/lBwzg3E/+u/MPGxFOeXzD2nodzvbw9mtj/wS+Cr7r4j3tktX2Z2DrDN3VeZ2cmJwylOLes/dwhx4Lv7aamOm9lwYAiwOviLMBD4s5mNJN4LGJR0+kBgS46bmjWd3XOCmU0CzgFO9X+P1y3pe05Dud9fO2ZWQTzsF7r7g8Hh183sSHffGpQotxWuhTkxBjjPzM4C9gUOJN7jrzKz3kEvv6z/3BNU0unA3de4+2HuPtjdBxMPhJPc/e/AEuDyYLTOaODtxH+FS52ZnQlMA85z951Jby0BLjGzfcxsCPEH1s8Voo058idgaDBiow/xB9RLCtymnAjq1ncD69z9u0lvLQEmBT9PAh7Kd9tyyd1nuPvA4O/zJcBT7n4p8DRwQXBa2d13KqHt4e+lR4CziD+43Al8vrDNyaofAPsAjwf/s6l39yvdvdHMFgNriZd6rnL31gK2M6vcfZeZfQlYBkSAe9y9scDNypUxwGeBNWb2fHDsemAOsNjMJhMflXZhgdqXb9OARWY2G2gg/o9hWdNMWxGRkFBJR0QkJBT4IiIhocAXEQkJBb6ISEgo8EVEQkKBLyISEgp8EZGQUOCLiITE/wdrhCnKwcO0MgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2_demean[:, 0], X2_demean[:, 1])\n",
    "plt.plot([0, w2[0]*30], [0, w2[1]*30], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.80000044,  0.59999941])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
